package run.newbug.Pro2.security.config.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.core.Authentication;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class SuccessFailureHandlerCodes {
    public static void getSuccessFailureMethods(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse,
                                         Authentication authentication) throws IOException {
        //设置响应数据的编码
        httpServletResponse.setCharacterEncoding("utf-8");
        //告诉客户端响应数据的类型,以及客户端以怎样的编码进行显示
        httpServletResponse.setContentType("application/json;charset=utf-8");
        //获取一个输出流对象
        PrintWriter out=httpServletResponse.getWriter();
        //向客户端输出一个json格式字符串
//        out.println("{\"state\":200,\"msg\":\"ok\"}");
        Map<String,Object> map = new HashMap<>();
        map.put("state", 200);
        map.put("msg", "OK,You MotherFucker");
        String s = new ObjectMapper().writeValueAsString(map);
        System.out.println(s);
        out.println(s);
        out.flush();
    }
}
